﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using YiYiTong.Rocket.EFDBFirst;
using YiYiTong.Rocket.Entity;

namespace YiYiTong.Rocket.Model.ParamModel
{
    /// <summary>
    /// 添加商品临时导入信息
    /// </summary>
    public class AddTempProductModel : BaseParamModel
    {
        //压缩列表的id，默认0
        public long zip_id { get; set; }
        /// <summary>
        /// 首图地址
        /// </summary>
        public string first_img { get; set; }

        //根据板块，如果是竞价则是竞价的jingjia_id 如果是活动则是活动的huodong_id
        public GoodsBusinessModel goodsBusinessModel { get; set; } = new GoodsBusinessModel();
        //临时对象
        public ADZ_GoodsTemp aDZ_GoodsTemp { get; set; } = new ADZ_GoodsTemp();
        //标签
        public ADZ_GoodsLabel aDZ_GoodsLabel { get; set; } = new ADZ_GoodsLabel();
        //分类
        public ADZ_GoodsCategory aDZ_GoodsCategory { get; set; } = new ADZ_GoodsCategory();
        //供应商
        public ADZ_SupplierMaster aDZ_SupplierMaster { get; set; } = new ADZ_SupplierMaster();
        //物料来源
        public ADZ_SupplierMaster aDZ_MaterialSource { get; set; } = new ADZ_SupplierMaster();
        //品牌
        public ADZ_BrandMaster aDZ_BrandMaster { get; set; } = new ADZ_BrandMaster();

        //商品信息
        public ADZ_GoodsMaster aDZ_GoodsMaster { get; set; } = new ADZ_GoodsMaster();

        //图片信息
        public List<ADZ_GoodsIMG> aDZ_GoodsIMGs { get; set; } = new List<ADZ_GoodsIMG>();

        public List<string> img_urls { get; set; } = new List<string>();

        public Tuple<bool, string> CheckAdd()
        {
            StringBuilder strResult = new StringBuilder();
            if (aDZ_GoodsLabel == null)
                strResult.Append("板块不能为空，");
            else
            {
                if (!aDZ_GoodsLabel.label_type.HasValue)
                    strResult.Append("板块类型未设置，");
                if (aDZ_GoodsLabel.label_type == (byte)ADZ_GoodsLabel_label_type.YuRe)
                {
                    if (aDZ_GoodsLabel.end_time == null)
                        strResult.Append("预热商品需要配置结束时间，");
                }
            }

            if (aDZ_GoodsCategory == null)
                strResult.Append("分类不能为空，");
            else
            {
                if (aDZ_GoodsCategory.category_id == 0 && string.IsNullOrWhiteSpace(aDZ_GoodsCategory.category_name))
                    strResult.Append("分类不能为空，");
            }

            if (aDZ_SupplierMaster == null)
                strResult.Append("供应商不能为空，");
            else
            {
                if (aDZ_SupplierMaster.supplier_id <= 0 && string.IsNullOrWhiteSpace(aDZ_SupplierMaster.supplier_name))
                    strResult.Append("供应商不能为空，");
            }

            if (aDZ_MaterialSource == null)
                strResult.Append("物料来源不能为空，");
            else
            {
                if (aDZ_MaterialSource.supplier_id <= 0 && string.IsNullOrWhiteSpace(aDZ_MaterialSource.supplier_name))
                    strResult.Append("物料来源不能为空，");
            }

            if (aDZ_BrandMaster == null)
                strResult.Append("品牌不能为空，");
            else
            {
                if (aDZ_BrandMaster.brand_id == 0 && string.IsNullOrWhiteSpace(aDZ_BrandMaster.brand_name))
                    strResult.Append("品牌不能为空，");
            }

            if (aDZ_GoodsMaster == null)
                strResult.Append("信息不能为空，");
            else
            {
                if (string.IsNullOrWhiteSpace(aDZ_GoodsMaster.MPN))
                    strResult.Append("料号不能为空，");
                if (string.IsNullOrWhiteSpace(aDZ_GoodsMaster.goods_unit))
                    strResult.Append("单位不能为空，");
                else
                {
                    //转为大写
                    aDZ_GoodsMaster.goods_unit = aDZ_GoodsMaster.goods_unit.Trim().ToUpper();
                    if (aDZ_GoodsMaster.goods_unit != "K" && aDZ_GoodsMaster.goods_unit != "PCS")
                        strResult.Append("单位只能是K或者PCS，");
                }

                if (string.IsNullOrWhiteSpace(aDZ_GoodsMaster.DCN))
                    strResult.Append("DC号不能为空，");

                if (!aDZ_GoodsMaster.currency_type.HasValue)
                    strResult.Append("币种不能为空，");
                else
                {
                    if (aDZ_GoodsMaster.currency_type.Value < 0 || aDZ_GoodsMaster.currency_type.Value > 1)
                        strResult.Append("币种只能为0或1，");
                }

                if (string.IsNullOrWhiteSpace(aDZ_GoodsMaster.MPN))
                    strResult.Append("料号不能为空，");
                if (!(aDZ_GoodsMaster.stock_amount > 0))
                    strResult.Append("库存数量不能为空，");
                if (!aDZ_GoodsMaster.min_amount.HasValue || aDZ_GoodsMaster.min_amount <= 0)
                    aDZ_GoodsMaster.min_amount = aDZ_GoodsMaster.stock_amount;


                ///直播的也可以没有价格，但是可以设置市场价，有价格的一定要设置市场价
                //if (aDZ_GoodsLabel.label_type == (byte)ADZ_GoodsLabel_label_type.ZhiBo)
                //{
                //    if (!aDZ_GoodsMaster.price.HasValue || aDZ_GoodsMaster.price <= 0)
                //        strResult.Append("直播价格不能为空，");
                //    if (!aDZ_GoodsMaster.market_price.HasValue || aDZ_GoodsMaster.market_price <= 0)
                //        strResult.Append("直播市场价格不能为空，");
                //}
                //if (aDZ_GoodsLabel.label_type == (byte)ADZ_GoodsLabel_label_type.YuRe)
                //{
                //if (aDZ_GoodsMaster.price > 0)
                //{
                //    if (!aDZ_GoodsMaster.market_price.HasValue || aDZ_GoodsMaster.market_price <= 0)
                //        strResult.Append("设置了价格请设置市场价，");
                //}
                //}
            }


            bool ret = strResult.Length == 0;
            if (!ret)
                strResult.Remove(strResult.Length - 1, 1);
            return new Tuple<bool, string>(ret, strResult.ToString());
        }
    }
}